package cs340.stormtroopers.junitTests.phase4BlackBox;

import junit.framework.*;
import cs340.stormtroopers.hypeerweb.*;
import cs340.stormtroopers.junitTests.*;

/**
 * Black Box test for the HyPeerWeb's removeNodeByReference.
 * Tests to ensure that removeNodeByReference works properly
 * 
 * @author Daniel Howard
 */
public class RemoveNodeByReferenceTest extends TestCase
{
	private final int MAX_SIZE = 32;
	private HyPeerWeb hypeerweb;
	
	public static Test suite()
	{
		return new TestSuite(RemoveNodeByReferenceTest.class);
	}
	
	public RemoveNodeByReferenceTest()
	{
		super();
	}
	
	public void setUp()
	{
		hypeerweb = HyPeerWeb.getSingleton();
		//hypeerweb.addNode(new Node(0));
		
		for(int i = 0; i < MAX_SIZE; i++)
		{
			hypeerweb.addAnotherNode();
		}
	}
	
	public void tearDown()
	{
		hypeerweb.clear();
	}
	
	/**
	 * Test for the removeNodeByReference method in HyPeerWeb
	 */
	public void test()
	{
		//hypeerweb id value of -5 (invalid--too low)
		hypeerweb.removeNodeByReference(-5);
		assertTrue(hypeerweb.size() == MAX_SIZE);
		
		//hypeerweb id value of 50 (invalid--too high)
		hypeerweb.removeNodeByReference(50);
		assertTrue(hypeerweb.size() == MAX_SIZE);
		
		//hypeerweb id value of 10 (valid)
		hypeerweb.removeNodeByReference(10);
		assertTrue(hypeerweb.size() == MAX_SIZE - 1);
		
		//restore hypeerweb to starting size
		hypeerweb.addAnotherNode();
		assertTrue(hypeerweb.size() == MAX_SIZE);
		
		
		//BOUNDARY VALUES
		//Lower Bound:
		hypeerweb.removeNodeByReference(-1);
		assertTrue(hypeerweb.size() == MAX_SIZE);
		
		hypeerweb.removeNodeByReference(0);
		assertTrue(hypeerweb.size() == MAX_SIZE - 1);
		
		//restore hypeerweb to starting size
		hypeerweb.addAnotherNode();
		assertTrue(hypeerweb.size() == MAX_SIZE);
		
		hypeerweb.removeNodeByReference(1);
		assertTrue(hypeerweb.size() == MAX_SIZE - 1);
		
		//restore hypeerweb to starting size
		hypeerweb.addAnotherNode();
		assertTrue(hypeerweb.size() == MAX_SIZE);
		
		//Upper Bound:
		hypeerweb.removeNodeByReference(32);
		assertTrue(hypeerweb.size() == MAX_SIZE);
		
		hypeerweb.removeNodeByReference(31);
		assertTrue(hypeerweb.size() == MAX_SIZE - 1);
		
		//restore hypeerweb to starting size
		hypeerweb.addAnotherNode();
		assertTrue(hypeerweb.size() == MAX_SIZE);
		
		hypeerweb.removeNodeByReference(30);
		assertTrue(hypeerweb.size() == MAX_SIZE - 1);
	}
	
	public static void main(String args[])
	{
		junit.textui.TestRunner.run(suite());
	}
}
